//
//  VoiceWaveView.m
//  ToListenPhone
//
//  Created by zhibao on 2022/11/29.
//

#import "NoticePointView.h"
#define  kLineWidth 1.f
@implementation NoticePointView

- (void)setPointArray:(NSArray *)pointArray{
    _pointArray = pointArray;
    [self setNeedsDisplay];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame: frame];
    if(self){
        self.clearsContextBeforeDrawing = YES;
    }
    return self;
}

- (void)drawRect:(CGRect)rect{
    if(self.pointArray.count == 0){
        return;
    }
    
    CGContextRef ref = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref, kLineWidth);
    CGContextBeginPath(ref);
    CGContextSetStrokeColorWithColor(ref, MyColor(self.colorStr).CGColor);
    for(int i = 0;i <self.pointArray.count;i++){
        CGPoint point = [[_pointArray objectAtIndex:i] CGPointValue];
        CGContextMoveToPoint(ref, i * kLineWidth * 2, self.height);
        CGContextAddLineToPoint(ref, i * kLineWidth * 2, self.height - point.y);
    }
    CGContextStrokePath(ref);
}

@end
